{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius" id="sou" href="{:url('/admin/order_refund/get_excel',$searchCondition)}">导出Excel</a>
            <a class="btn btn-primary radius" id="xuan" style="display: none;" href="javascript:;" onclick="xuan()">导出Excel</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        <?php use think\Db;?>
        {volist name="list" id="vo" key="k"}
        <tr class="text-c">
            {include file="td" /}
            <td class="f-14">
                <a href="javascript:;" onclick="del('{$vo.id}')" class="label label-warning radius"
                   title="删除">删除</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
{/block}
{block name="script"}

<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="__LIB__/template/template.js"></script>
<script>
    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked", this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked) {
            $('#xuan').css('display', 'inline-block') // 显示选择excel导出数据
            $('#sou').css('display', 'none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display', 'none')
            $('#sou').css('display', 'inline-block')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData = $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display', 'inline-block') // 显示选择excel导出数据
            $('#sou').css('display', 'none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display', 'none')
            $('#sou').css('display', 'inline-block')
            $('#checkAlls').prop('checked', false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search', value: 'all'})
        // console.log('选择的数据是', checkData.length)
        // console.log('选择的数据是', checkData.serializeArray())
        // console.log('选择的数组是', dataArr)
        $.ajax({
            type: 'post',
            url: '/admin/order_refund/get_excel',
            data: dataArr,
            success: function (res) {
                console.log('res',res)
                if (res.code == 5) {
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('导出Excel数据', '/admin/pub/role/id/1')
                }
            }
        });
    }

    function del(id) {
        layer.confirm("此操作将永久删除此记录，确定进行操作？", {
            btn: ['确定', '取消'],
            title: '提示',
            icon: 3
        }, function () {
            var url = '/admin/order_refund/delete?id='+id;
            $.post(url, '', function (data) {
                if (data.code == 0) {
                    layer.msg("已清空", {icon: 1, time: 2000});
                    window.location.reload();
                } else {
                    layer.alert(data.msg);
                }
            }, 'json')
        }, function (index) {
            layer.close(index);
        });
    }

</script>
{/block}
